// FlyBehavior 接口
interface FlyBehavior {
    void fly();
}

// FreeFly 类实现 FlyBehavior 接口
class FreeFly implements FlyBehavior {
    @Override
    public void fly() {
        System.out.println("自由地在天空飞翔！");
    }
}

// UnableFly 类实现 FlyBehavior 接口
class UnableFly implements FlyBehavior {
    @Override
    public void fly() {
        System.out.println("扑腾几下飞不起来！");
    }
}

// SwimBehavior 接口
interface SwimBehavior {
    void swim();
}

// AbleSwim 类实现 SwimBehavior 接口
class AbleSwim implements SwimBehavior {
    @Override
    public void swim() {
        System.out.println("像鱼一样在水中游翔浅底！");
    }
}

// UnableSwim 类实现 SwimBehavior 接口
class UnableSwim implements SwimBehavior {
    @Override
    public void swim() {
        System.out.println("扑腾几下就淹死了！");
    }
}

// Bird 抽象类
abstract class Bird {
    protected FlyBehavior flyBehavior;
    protected SwimBehavior swimBehavior;

    public Bird(FlyBehavior flyBehavior, SwimBehavior swimBehavior) {
        this.flyBehavior = flyBehavior;
        this.swimBehavior = swimBehavior;
    }

    public abstract void display();

    public void performFly() {
        flyBehavior.fly();
    }

    public void performSwim() {
        swimBehavior.swim();
    }
}

// Pigeon 类继承 Bird
class Pigeon extends Bird {
    public Pigeon(FlyBehavior flyBehavior, SwimBehavior swimBehavior) {
        super(flyBehavior, swimBehavior);
    }

    @Override
    public void display() {
        System.out.println("我是鸽子。");
    }
}

// Eagle 类继承 Bird
class Eagle extends Bird {
    public Eagle(FlyBehavior flyBehavior, SwimBehavior swimBehavior) {
        super(flyBehavior, swimBehavior);
    }

    @Override
    public void display() {
        System.out.println("我是老鹰。");
    }
}

// Penguin 类继承 Bird
class Penguin extends Bird {
    public Penguin(FlyBehavior flyBehavior, SwimBehavior swimBehavior) {
        super(flyBehavior, swimBehavior);
    }

    @Override
    public void display() {
        System.out.println("我是企鹅。");
    }
}

// Client 类
public class Client {
    public static void main(String[] args) {
        // 创建 FreeFly 和 UnableSwim 行为的 Pigeon
        FlyBehavior freeFly = new FreeFly();
        SwimBehavior unableSwim = new UnableSwim();
        Bird pigeon = new Pigeon(freeFly, unableSwim);

        // 创建 FreeFly 和 UnableSwim 行为的 Eagle
        Bird eagle = new Eagle(freeFly, unableSwim);

        // 创建 UnableFly 和 AbleSwim 行为的 Penguin
        FlyBehavior unableFly = new UnableFly();
        SwimBehavior ableSwim = new AbleSwim();
        Bird penguin = new Penguin(unableFly, ableSwim);

        // 测试 Pigeon
        System.out.println("测试鸽子：");
        pigeon.display();
        pigeon.performFly();
        pigeon.performSwim();

        System.out.println();

        // 测试 Eagle
        System.out.println("测试老鹰：");
        eagle.display();
        eagle.performFly();
        eagle.performSwim();

        System.out.println();

        // 测试 Penguin
        System.out.println("测试企鹅：");
        penguin.display();
        penguin.performFly();
        penguin.performSwim();
    }
}
